<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\JjrUserProjectSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '客户管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="jjr-user-project-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('excel导出', ['export'], ['class' => 'btn btn-success']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
       // 'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            //'jjr_user_id',
            //'jjr_project_id',
            'client_real_name',
            'client_mobile',
            ['attribute'=>'client_gender','value'=>function($model){
                                    if($model['client_gender']==1){
                                        return '男';
                                    }else{
                                        return '女';
                                    }

                }],
            ['attribute'=>'process','value'=>function($model){
                if ($model['process'] == 1) {
                    return "报备";
                  } else if ($model['process'] == 2) {
                                    return "到访接待";
                  } else if ($model['process'] == 3) {
                                    return "认筹认购";
                  } else if ($model['process'] == 4) {
                                    return "签约";
                  } else if ($model['process'] == 5) {
                                    return "结款";
                  }

            }],
           // 'remark',
            ['label'=>'项目名称',  'value' => 'name' ],
            ['label'=>'经纪人',  'value' => 'real_name' ],
            //'process_remark',
            'create_time',
            //'update_time',
            [
                'attribute' => 'status',
                'value' => function($model) {//使用匿名函数格式化（参数为当前模型对象），也可以在模型类中定义该方法
                    $status = ['未审核', '已审核','未知'];
                    return $status[$model['status']];
                }
            ],

            ['class' => 'yii\grid\ActionColumn','template' => '{audit}{view}{update}{delete}','buttons' => [

                'audit' => function ($url,$model, $key) {
                    if($model['status']==1){
                        return Html::a('<span class="glyphicon glyphicon-remove-sign"></span>', $url, ['title'=> '取消审核'] );
                    }else if($model['status']==0){
                        return Html::a('<span class="glyphicon glyphicon-ok-sign"></span>', $url, ['title'=> '审核'] );

                    }



                }

            ],
                'urlCreator' => function ($action, $model, $key, $index) {
                    switch($action)
                    {
                        case 'audit':
                            if($model['status']==0){
                                return \yii\helpers\Url::toRoute('/jjr-user-project/audit?id='.$model['id']);
                            }else{
                                return \yii\helpers\Url::toRoute('/jjr-user-project/cancel-audit?id='.$model['id']);
                            }

                            break;
                        case 'update':
                            return \yii\helpers\Url::toRoute('/jjr-user-project/update?id='.$model['id']);
                            break;
                        case 'delete':
                            return \yii\helpers\Url::toRoute('/jjr-user-project/delete?id='.$model['id']);
                            break;
                        case 'view':
                            return \yii\helpers\Url::toRoute('/jjr-user-project/view?id='.$model['id']);
                            break;

                    }

                },

                'header' => '操作',

            ],
        ],
    ]); ?>
</div>

<!-- 定义数据块 -->
<?php $this->beginBlock('test'); ?>
jQuery(document).ready(function() {
highlight_subnav('jjr-user-project/index'); //子导航高亮
});
<?php $this->endBlock() ?>
<!-- 将数据块 注入到视图中的某个位置 -->
<?php $this->registerJs($this->blocks['test'], \yii\web\View::POS_END); ?>
